package com.uit.smarttool.ultility;

import java.util.ArrayList;
import java.util.HashMap;
import com.uit.smarttool.ultility.CustomHolder;
import com.uit.smarttool.activity.R;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import android.view.ViewGroup;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public class CustomCartView extends SimpleAdapter {
	
	private ArrayList<HashMap<String, String>> list;
	private final Activity activity;

	public CustomCartView(Activity activity, ArrayList<HashMap<String, String>> list) {
		super(activity, list, 0, null, null);
		this.activity = activity;
		this.list = list;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		final CustomHolder holder;
		LayoutInflater inflater = activity.getLayoutInflater();

		if (convertView == null) {
			convertView = inflater.inflate(R.layout.lv_cart, null);
			holder = new CustomHolder();
			holder.tvProduct = (TextView) convertView.findViewById(R.id.tvProduct);
			holder.tvPrice = (TextView) convertView.findViewById(R.id.tvPrice);
			holder.tvNumber = (TextView) convertView.findViewById(R.id.tvNumber);
			convertView.setTag(holder);
		} else {
			holder = (CustomHolder) convertView.getTag();
		}
		
		HashMap<String, String> map = list.get(position);
		holder.tvProduct.setText(map.get("Cot1"));
		holder.tvPrice.setText(map.get("Cot2"));
		holder.tvNumber.setText(map.get("Cot3"));
		
		return convertView;
	}
	

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
}
